package com.likeycy.my;

import com.likeycy.my.printer.BinaryTrees;
import com.likeycy.my.tree.AVLTree;

/**
 * @ClassName: TestMain
 * @Description: 测试自定义实现的二叉树
 * @Author: sodagreen
 * @Date: 2021/3/5 13:43
 * @Version: 1.0
 */
public class TestMain {

    public static Integer[] arrayInt = new Integer[] {
            7, 4, 2, 1, 3, 5, 9, 8, 11, 10, 12, 6
    };

    public static Integer[] numArray = new Integer[] {
            71, 49, 51, 81, 70, 84, 41, 22, 60, 73, 96, 72, 79, 88
    };

    public static void main(String[] args) {
        /*testMyBinarySearchTree1();
        testMyBinarySearchTree2();
        testMyBinarySearchTree3();*/

        testMyBinarySearchTreeByRemove();
    }

    public static void testMyBinarySearchTree3() {
        AVLTree<Object> binarySearchTree = new AVLTree<>();
        for (int i = 0; i < 30; i++) {
            binarySearchTree.add((int)(Math.random() * 100));
        }
        String str = BinaryTrees.printString(binarySearchTree);
        str += "\n\n";
        // 打印二叉树到文件查看。 true参数表示追加到文件末尾，不进行覆盖
        //Files.writeToFile("E:/RandomNumberTreePrint.txt", str, true);
    }

    public static void testMyBinarySearchTreeByAdd() {

        AVLTree<Integer> avlTree = new AVLTree<>();
        for (Integer num : numArray) {
            System.out.println("【" + num +"】");
            avlTree.add(num);
            BinaryTrees.println(avlTree);
            System.out.println("===================================================================");
        }
        avlTree.remove(71);
        BinaryTrees.println(avlTree);
    }

    public static void testMyBinarySearchTreeByRemove() {

        AVLTree<Integer> avlTree = new AVLTree<>();
        for (Integer num : numArray) {
            avlTree.add(num);
        }
        System.out.println("===================================================================");
        for (int i = 0; i < numArray.length; i++) {
            avlTree.remove(numArray[i]);
            System.out.println("【" + numArray[i] +"】");
            BinaryTrees.println(avlTree);
            System.out.println("===================================================================");
        }
    }
}
